package com.accp.vehiclecare.biz.zbbiz;


import com.accp.vehiclecare.dao.zbdao.DimissiontextMapper;
import com.accp.vehiclecare.dao.zbdao.EmployeeMapper;
import com.accp.vehiclecare.pojo.Dimissiontext;
import com.accp.vehiclecare.vo.zbvo.DimissionVo;
import com.accp.vehiclecare.vo.zbvo.StaffVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

@Service
public class DimissionBiz {
    @Autowired(required = false)
    private DimissiontextMapper ddao;

    @Autowired(required = false)
    private EmployeeMapper edao;

    /**
     * 查询全部的职工信息
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public PageInfo<StaffVo> queryStaff(Integer pageNum, Integer pageSize) {
        System.out.println(pageNum+"=="+pageSize);
        PageHelper.startPage(pageNum, pageSize);
        return new PageInfo<StaffVo>(edao.SelectAll());
    }

    /**
     * 查询全部的离职信息
     * @param p
     * @param s
     * @return
     */
    @Transactional(propagation = Propagation.SUPPORTS, isolation = Isolation.READ_COMMITTED, readOnly = true)
    public PageInfo<DimissionVo> queryDim(Integer p,Integer s){
        PageHelper.startPage(p,s);
        return new PageInfo<DimissionVo>(ddao.SelectAll());
    }

    /**
     * 删除指定的离职信息
     * @param eid
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean removeDim(Integer eid){
        return 0!=ddao.deleteByPrimaryKey(eid);
    }

    /**
     * 根据职工id修改离职状态
     * @param eid
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean modifyDim(Integer eid){
        return 0!=edao.updateDimission(eid);
    }
    /**
     * 根据职工id修改在职状态
     * @param eid
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean modifyWork(Integer eid){
        return 0!=edao.updateWork(eid);
    }

    /**
     * 离职信息新增
     * @param dim
     * @return
     */
    @Transactional(propagation = Propagation.REQUIRED)
    public boolean addDim(Dimissiontext dim){
        return 0!=ddao.insertSelective(dim);
    }
}
